/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.pfs.Tph.conn;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author Administrator
 */
public class ConnectOdrace {

    /**
     * 
     * @param db_connect_string
     * @param db_userid
     * @param db_password
     * @return 
     */
    public static Connection dbConnect(String db_connect_string,
            String db_userid, String db_password) {
        try {
            DriverManager.registerDriver(
                    new oracle.jdbc.OracleDriver());

            Connection conn = DriverManager.getConnection(
                    db_connect_string, db_userid, db_password);

            System.out.println("connected");
            return conn;

        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    public static void main(String[] args) throws SQLException {
        // ket noi db
        Connection conn = dbConnect("jdbc:oracle:oci8:@dssnt01", "scott", "tiger");
        
        Statement stmt = conn.createStatement();
        
        ResultSet rset = stmt.executeQuery("select 'Hello OCI driver tester '||USER||'!' result from dual");
        
        while (rset.next()) {
            System.out.println("name: "+rset.getString(1));
        }
        rset.close();
        stmt.close();
        conn.close();
    }
}
